CSharpTest.Net
Equals(T,T) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Bases Namespace > Equatable<T> Class > Equals Method : Equals(T,T) Method

x
y

Glossary Item Box

Compares the two objects for non-reference equality

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function Equals( _
   ByVal x As T, _
   ByVal y As T _
) As Boolean
C# 
public static bool Equals( 
   T x,
   T y
)

Parameters

x
y

Example

Library/Library.Test/TestEquatable.cs

C#Copy Code
IEqualityComparer<Null<int>> cmp = Null<int>.Comparer;
Null<int> nil = null;
Null<int> a = 5;
Null<int> b1 = 6;
Null<int> b2 = 6;

Assert.IsTrue(cmp.Equals(null, nil));
Assert.IsTrue(cmp.Equals(nil, null));
Assert.IsTrue(cmp.Equals(b1, b2));
Assert.IsFalse(cmp.Equals(a, b1));
Assert.IsFalse(cmp.Equals(b1, a));
Assert.IsFalse(cmp.Equals(nil, a));
Assert.IsFalse(cmp.Equals(a, nil));
Assert.IsFalse(cmp.Equals(null, a));
Assert.IsFalse(cmp.Equals(a, null));

Assert.IsTrue(Null<int>.Equals(null, nil));
Assert.IsTrue(Null<int>.Equals(nil, null));
Assert.IsTrue(Null<int>.Equals(b1, b2));
Assert.IsFalse(Null<int>.Equals(a, b1));
Assert.IsFalse(Null<int>.Equals(b1, a));
Assert.IsFalse(Null<int>.Equals(nil, a));
Assert.IsFalse(Null<int>.Equals(a, nil));
Assert.IsFalse(Null<int>.Equals(null, a));
Assert.IsFalse(Null<int>.Equals(a, null));

Assert.AreNotEqual(a.GetHashCode(), b2.GetHashCode());
Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());

Assert.AreEqual(cmp.GetHashCode(nil), 0);
Assert.AreEqual(cmp.GetHashCode(a), a.GetHashCode());
Assert.AreEqual(cmp.GetHashCode(b1), b2.GetHashCode());

Assert.AreEqual(Null<int>.GetHashCode(nil), 0);
Assert.AreEqual(Null<int>.GetHashCode(a), a.GetHashCode());
Assert.AreEqual(Null<int>.GetHashCode(b1), b2.GetHashCode());
VB.NETCopy Code
Dim cmp As IEqualityComparer(Of Null(Of Integer)) = Null(Of Integer).Comparer
Dim nil As Null(Of Integer) = Nothing
Dim a As Null(Of Integer) = 5
Dim b1 As Null(Of Integer) = 6
Dim b2 As Null(Of Integer) = 6

Assert.IsTrue(cmp.Equals(Nothing, nil))
Assert.IsTrue(cmp.Equals(nil, Nothing))
Assert.IsTrue(cmp.Equals(b1, b2))
Assert.IsFalse(cmp.Equals(a, b1))
Assert.IsFalse(cmp.Equals(b1, a))
Assert.IsFalse(cmp.Equals(nil, a))
Assert.IsFalse(cmp.Equals(a, nil))
Assert.IsFalse(cmp.Equals(Nothing, a))
Assert.IsFalse(cmp.Equals(a, Nothing))

Assert.IsTrue(Null(Of Integer).Equals(Nothing, nil))
Assert.IsTrue(Null(Of Integer).Equals(nil, Nothing))
Assert.IsTrue(Null(Of Integer).Equals(b1, b2))
Assert.IsFalse(Null(Of Integer).Equals(a, b1))
Assert.IsFalse(Null(Of Integer).Equals(b1, a))
Assert.IsFalse(Null(Of Integer).Equals(nil, a))
Assert.IsFalse(Null(Of Integer).Equals(a, nil))
Assert.IsFalse(Null(Of Integer).Equals(Nothing, a))
Assert.IsFalse(Null(Of Integer).Equals(a, Nothing))

Assert.AreNotEqual(a.GetHashCode(), b2.GetHashCode())
Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode())

Assert.AreEqual(cmp.GetHashCode(nil), 0)
Assert.AreEqual(cmp.GetHashCode(a), a.GetHashCode())
Assert.AreEqual(cmp.GetHashCode(b1), b2.GetHashCode())

Assert.AreEqual(Null(Of Integer).GetHashCode(nil), 0)
Assert.AreEqual(Null(Of Integer).GetHashCode(a), a.GetHashCode())
Assert.AreEqual(Null(Of Integer).GetHashCode(b1), b2.GetHashCode())

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys